import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * model - 条目配置
 * @date: 2019-01-28
 */
import { getResponse, createPagination } from 'utils/utils';
import { queryIdpValue } from 'cpaas-front/lib/services/api';
import { queryClause as _queryClause, addClause as _addClause, updateClause as _updateClause, cardTenantQueryPage, cardTenantInsert, cardTenantDelete, queryClauseDetail as _queryClauseDetail, fetchHead as _fetchHead, fetchTable as _fetchTable, saveClause as _saveClause, fetchCard as _fetchCard, deleteCard as _deleteCard } from "../services/dashboardClauseService";
export default {
  namespace: 'dashboardClause',
  state: {
    flags: [],
    clauseList: [],
    // 条目配置查询数据
    clausePagination: {},
    // 条目配置查询分页参数
    clauseDetail: {},
    clauseDetailHead: {},
    // 条目配置明细
    clauseDetailTableList: [],
    // 条目详情列表
    clauseDetailPagination: {},
    // 条目详情分页
    cardList: [],
    // 卡片列表
    cardPagination: {} // 卡片分页

  },
  effects: {
    // 查询值集
    init: /*#__PURE__*/_regeneratorRuntime.mark(function init(params, _ref) {
      var call, put, flags;
      return _regeneratorRuntime.wrap(function init$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              call = _ref.call, put = _ref.put;
              _context.t0 = getResponse;
              _context.next = 4;
              return call(queryIdpValue, 'CPFM.DATA_TENANT_LEVEL');

            case 4:
              _context.t1 = _context.sent;
              flags = (0, _context.t0)(_context.t1);
              _context.next = 8;
              return put({
                type: 'updateState',
                payload: {
                  flags: flags || []
                }
              });

            case 8:
            case "end":
              return _context.stop();
          }
        }
      }, init);
    }),
    // 查询条目配置列表
    queryClause: /*#__PURE__*/_regeneratorRuntime.mark(function queryClause(_ref2, _ref3) {
      var payload, call, put, data;
      return _regeneratorRuntime.wrap(function queryClause$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref2.payload;
              call = _ref3.call, put = _ref3.put;
              _context2.t0 = getResponse;
              _context2.next = 5;
              return call(_queryClause, payload);

            case 5:
              _context2.t1 = _context2.sent;
              data = (0, _context2.t0)(_context2.t1);

              if (!data) {
                _context2.next = 10;
                break;
              }

              _context2.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  clauseList: data.content,
                  clausePagination: createPagination(data)
                }
              });

            case 10:
            case "end":
              return _context2.stop();
          }
        }
      }, queryClause);
    }),
    // 查询条目配置列表
    queryClauseDetail: /*#__PURE__*/_regeneratorRuntime.mark(function queryClauseDetail(_ref4, _ref5) {
      var payload, call, put, data;
      return _regeneratorRuntime.wrap(function queryClauseDetail$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref4.payload;
              call = _ref5.call, put = _ref5.put;
              _context3.t0 = getResponse;
              _context3.next = 5;
              return call(_queryClauseDetail, payload);

            case 5:
              _context3.t1 = _context3.sent;
              data = (0, _context3.t0)(_context3.t1);

              if (!data) {
                _context3.next = 10;
                break;
              }

              _context3.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  clauseDetail: data
                }
              });

            case 10:
              return _context3.abrupt("return", data);

            case 11:
            case "end":
              return _context3.stop();
          }
        }
      }, queryClauseDetail);
    }),
    // 添加条目配置
    addClause: /*#__PURE__*/_regeneratorRuntime.mark(function addClause(_ref6, _ref7) {
      var payload, call, orderType;
      return _regeneratorRuntime.wrap(function addClause$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref6.payload;
              call = _ref7.call;
              _context4.next = 4;
              return call(_addClause, payload);

            case 4:
              orderType = _context4.sent;
              return _context4.abrupt("return", getResponse(orderType));

            case 6:
            case "end":
              return _context4.stop();
          }
        }
      }, addClause);
    }),
    // 添加条目配置
    updateClause: /*#__PURE__*/_regeneratorRuntime.mark(function updateClause(_ref8, _ref9) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function updateClause$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              payload = _ref8.payload;
              call = _ref9.call;
              _context5.next = 4;
              return call(_updateClause, payload);

            case 4:
              res = _context5.sent;
              return _context5.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context5.stop();
          }
        }
      }, updateClause);
    }),
    // 查询已经分配的租户
    cardTenantFetch: /*#__PURE__*/_regeneratorRuntime.mark(function cardTenantFetch(_ref10, _ref11) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function cardTenantFetch$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              payload = _ref10.payload;
              call = _ref11.call;
              _context6.next = 4;
              return call(cardTenantQueryPage, payload);

            case 4:
              res = _context6.sent;
              return _context6.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context6.stop();
          }
        }
      }, cardTenantFetch);
    }),
    cardTenantAdd: /*#__PURE__*/_regeneratorRuntime.mark(function cardTenantAdd(_ref12, _ref13) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function cardTenantAdd$(_context7) {
        while (1) {
          switch (_context7.prev = _context7.next) {
            case 0:
              payload = _ref12.payload;
              call = _ref13.call;
              _context7.next = 4;
              return call(cardTenantInsert, payload);

            case 4:
              res = _context7.sent;
              return _context7.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context7.stop();
          }
        }
      }, cardTenantAdd);
    }),
    cardTenantRemove: /*#__PURE__*/_regeneratorRuntime.mark(function cardTenantRemove(_ref14, _ref15) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function cardTenantRemove$(_context8) {
        while (1) {
          switch (_context8.prev = _context8.next) {
            case 0:
              payload = _ref14.payload;
              call = _ref15.call;
              _context8.next = 4;
              return call(cardTenantDelete, payload);

            case 4:
              res = _context8.sent;
              return _context8.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context8.stop();
          }
        }
      }, cardTenantRemove);
    }),
    // 查询卡片明细头
    fetchHead: /*#__PURE__*/_regeneratorRuntime.mark(function fetchHead(_ref16, _ref17) {
      var payload, call, put, data;
      return _regeneratorRuntime.wrap(function fetchHead$(_context9) {
        while (1) {
          switch (_context9.prev = _context9.next) {
            case 0:
              payload = _ref16.payload;
              call = _ref17.call, put = _ref17.put;
              _context9.next = 4;
              return call(_fetchHead, payload);

            case 4:
              data = _context9.sent;

              if (!data) {
                _context9.next = 8;
                break;
              }

              _context9.next = 8;
              return put({
                type: 'updateState',
                payload: {
                  clauseDetailHead: data
                }
              });

            case 8:
            case "end":
              return _context9.stop();
          }
        }
      }, fetchHead);
    }),
    // 查询明细table
    fetchTable: /*#__PURE__*/_regeneratorRuntime.mark(function fetchTable(_ref18, _ref19) {
      var payload, call, put, data;
      return _regeneratorRuntime.wrap(function fetchTable$(_context10) {
        while (1) {
          switch (_context10.prev = _context10.next) {
            case 0:
              payload = _ref18.payload;
              call = _ref19.call, put = _ref19.put;
              _context10.next = 4;
              return call(_fetchTable, payload);

            case 4:
              data = _context10.sent;

              if (!data) {
                _context10.next = 8;
                break;
              }

              _context10.next = 8;
              return put({
                type: 'updateState',
                payload: {
                  clauseDetailTableList: data.content,
                  clauseDetailPagination: createPagination(data)
                }
              });

            case 8:
            case "end":
              return _context10.stop();
          }
        }
      }, fetchTable);
    }),
    // 保存条目
    saveClause: /*#__PURE__*/_regeneratorRuntime.mark(function saveClause(_ref20, _ref21) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function saveClause$(_context11) {
        while (1) {
          switch (_context11.prev = _context11.next) {
            case 0:
              payload = _ref20.payload;
              call = _ref21.call;
              _context11.next = 4;
              return call(_saveClause, payload);

            case 4:
              res = _context11.sent;
              return _context11.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context11.stop();
          }
        }
      }, saveClause);
    }),
    // 删除卡片
    deleteCard: /*#__PURE__*/_regeneratorRuntime.mark(function deleteCard(_ref22, _ref23) {
      var payload, call, res;
      return _regeneratorRuntime.wrap(function deleteCard$(_context12) {
        while (1) {
          switch (_context12.prev = _context12.next) {
            case 0:
              payload = _ref22.payload;
              call = _ref23.call;
              _context12.next = 4;
              return call(_deleteCard, payload);

            case 4:
              res = _context12.sent;
              return _context12.abrupt("return", getResponse(res));

            case 6:
            case "end":
              return _context12.stop();
          }
        }
      }, deleteCard);
    }),
    // 查询卡片
    fetchCard: /*#__PURE__*/_regeneratorRuntime.mark(function fetchCard(_ref24, _ref25) {
      var payload, call, put, data;
      return _regeneratorRuntime.wrap(function fetchCard$(_context13) {
        while (1) {
          switch (_context13.prev = _context13.next) {
            case 0:
              payload = _ref24.payload;
              call = _ref25.call, put = _ref25.put;
              _context13.next = 4;
              return call(_fetchCard, payload);

            case 4:
              data = _context13.sent;

              if (!data) {
                _context13.next = 8;
                break;
              }

              _context13.next = 8;
              return put({
                type: 'updateState',
                payload: {
                  cardList: data.content,
                  cardPagination: createPagination(data)
                }
              });

            case 8:
            case "end":
              return _context13.stop();
          }
        }
      }, fetchCard);
    })
  },
  reducers: {
    updateState: function updateState(state, _ref26) {
      var payload = _ref26.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};